using Demo.Gateway;
using IdentityServer4.AccessTokenValidation;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;;

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("ocelot.json");
Action<IdentityServerAuthenticationOptions> optionsAuth = o =>
{
    o.Authority = builder.Configuration["AuthService"];
    o.SupportedTokens = SupportedTokens.Jwt;
    o.ApiSecret = "secret";
    o.RequireHttpsMetadata = false;
    o.JwtValidationClockSkew = TimeSpan.FromSeconds(0);
};
builder.Services.AddAuthentication()
    .AddIdentityServerAuthentication("DemoAuth", optionsAuth);

builder.Services.AddOcelot();

var app = builder.Build();
app.UseAuthentication();
app.UseJwtTokenMiddleware("DemoAuth");
app.UseOcelot().Wait();
app.Run();
